home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 3 / Amiga Format CD03 (1996-07-04)(Future Publishing)(GB)(Track 1 of 6)[!][issue 1996-08].iso / comms / netsoftware / nethandler.lha / NetHandler / netcomm.h < prev    next >
C/C++ Source or Header  |  1989-09-16  |  7KB  |  199 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2. /* |_o_o|\\ Copyright (c) 1988, 1989 The Software Distillery.  All Rights  */
  3. /* |. o.| || Reserved.  This program may not be distributed without the    */
  4. /* | .  | || permission of the authors:                            BBS:    */
  5. /* | o  | ||   John Toebes     Doug Walker    Dave Baker                   */
  6. /* |  . |//                                                                */
  7. /* ======                                                                  */
  8. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  9.  
  10.  
  11. /* If PARANOID is defined >0, requesters will pop up for debugging */
  12. /* during the startup.  No need to define it unless we die before  */
  13. /* getting far enough to start up debugging.                       */
  14.  
  15. #define PARANOID 0
  16.  
  17. /* Defining CPR >0 will link in code to do a busy wait when the CPRWAIT */
  18. /* debug packet is received.  This allows CPR to catch the NET: task    */
  19. /* and lets us proceed with debugging;  if we are WAITing when CPR      */
  20. /* catches us, we're dead in the water.                                 */
  21. #define CPR 0
  22.  
  23. /* Defining DEBUG >0 will link in code to print stuff to any debugging  */
  24. /* filehandles provided us by HANDD.  This slows us down quite a bit    */
  25. /* since the BUG macros all call a subroutine to print their messages   */
  26. /* even if we aren't debugging anything at the moment.                  */
  27.  
  28. #ifdef DEBUG
  29. #undef DEBUG
  30. #endif
  31.  
  32. #define DEBUG 0
  33.  
  34.  
  35. /* The NOEXT define is set by the including .c program to prevent system */
  36. /* include files from being reincluded here.  It is only used in dnetlib */
  37. #ifndef NOEXT
  38. #include <exec/types.h>
  39. #include <exec/nodes.h>
  40. #include <exec/lists.h>
  41. #include <exec/ports.h>
  42. #include <exec/libraries.h>
  43. #include <exec/devices.h>
  44. #include <exec/io.h>
  45. #include <exec/memory.h>
  46. #include <exec/interrupts.h>
  47. #include <intuition/intuition.h>
  48. #include <devices/console.h>
  49. #include <devices/timer.h>
  50. #include <libraries/dos.h>
  51. #include <libraries/dosextens.h>
  52. #include <libraries/filehandler.h>
  53. #include <string.h>
  54. #include <stdlib.h>
  55. #ifdef MANX
  56. #define U_ARGS(a) ()    /* No support for prototypes - oh well */
  57. #else
  58. #define U_ARGS(a) a     /* prototype checking to ensure all is well */
  59. #include <proto/exec.h>
  60. #include <proto/dos.h>
  61. #include <proto/timer.h>
  62. #endif
  63. #endif
  64.  
  65. #ifndef min
  66. #define min(a,b) ((a)<(b)?(a):(b))
  67. #endif
  68.  
  69. /* A macro to make good SAS Institute programmers feel at home */
  70. #define MQ(f,t,l) memcpy((char *)t,(char *)f,(int)l);
  71.  
  72. #define MBSTR(f,t) memcpy((char *)t,(char *)f,(int)(*((char *)f))+1);
  73. #define BSTRLEN(s) ((int)(*((char *)(s))))
  74.  
  75. #undef GLOBAL
  76. /* my version of BADDR() has no problems with casting */
  77. #undef  BADDR
  78. #define BADDR(x)        ((APTR)((long)x << 2))
  79. #define MKBADDR(x)      ((BPTR)((long)x >> 2))
  80.  
  81. /* Define a few packet types that may not be in the system include files */
  82.  
  83. #ifdef ACTION_END
  84. #undef ACTION_END
  85. #endif
  86. #ifdef ACTION_SEEK
  87. #undef ACTION_SEEK
  88. #endif
  89.  
  90. #define ACTION_FIND_WRITE       1004L
  91. #define ACTION_FIND_INPUT       1005L /* please refer to DOS Tech. Ref. */
  92. #define ACTION_FIND_OUTPUT      1006L
  93. #define ACTION_END              1007L
  94. #define ACTION_SEEK             1008L
  95. #ifndef ACTION_MORE_CACHE
  96. #define ACTION_MORE_CACHE       18L
  97. #endif
  98. #ifndef ACTION_FLUSH
  99. #define ACTION_FLUSH            27L
  100. #endif
  101. #define ACTION_SET_FILE_DATE    34L
  102. #define ACTION_SET_RAW_MODE     994L
  103.  
  104. /* Private packets */
  105. #define ACTION_HANDLER_DEBUG    2010L
  106. #define ACTION_SET_TRANS_TYPE   2011L
  107. #define ACTION_NETWORK_HELLO    2012L
  108.  
  109.  
  110. #define ACTION_NETWORK_KLUDGE   4674764L   /* Temporary until ROOT: done */
  111.  
  112.  
  113. #define ERROR_NODE_DOWN   ERROR_OBJECT_NOT_FOUND
  114.  
  115. #define DOS_FALSE        0L
  116. #define DOS_TRUE        -1L           /* BCPL "TRUE" */
  117.  
  118. typedef char *RPTR;    /* Pointer to remote node's memory    */
  119.  
  120. typedef int (*fptr)();
  121.  
  122. #define RNAMELEN 16    /* Max 16 byte names for remote nodes */
  123.  
  124. typedef struct TimerPacket {
  125.    struct timerequest tm_req;
  126.    struct DosPacket   tm_pkt;
  127. };
  128.  
  129.  
  130. /* Define a struct to communicate with the NETSTAT program */
  131. #define NTI_TRANSMIT 0 
  132. #define NTI_RECEIVE  1
  133.  
  134. struct NetTransInfo
  135. {
  136.    struct Message m;
  137.    long nti_bytes;      /* Number of bytes since last request */
  138.    int  nti_direction;  /* NTI_TRANSMIT or NTI_RECEIVE        */
  139. };
  140.  
  141. /* The following defines the network buffer size.  Reads/writes larger */
  142. /* than this amount will be broken up into smaller chunks.             */
  143. /* Really should be set by querying the other side.                    */
  144. #define NETBUFSIZE 1024   /* Maximum amount of meaningful data to send */
  145. #define FILENAMELEN 120  /* Length of a filename */
  146.  
  147. struct RPacket       /* Packet sent to remote node */
  148. {
  149.    LONG Type;          /* Type of request (AmigaDos packet type)       */
  150.    RPTR RDevice;       /* Pointer to remote MsgPort to send packet to  */
  151.    LONG Arg1,          /* Equivalent to dp_Arg? in normal devices      */
  152.         Arg2,          /* when transmitting, dp_Res? when receiving    */
  153.         Arg3,
  154.         Arg4;
  155.    long DLen;          /* Length of data in Data buffer                */
  156.    char Data[NETBUFSIZE]; /* Data buffer                               */
  157. };
  158.  
  159. #define RPSIZE (sizeof(struct RPacket) - NETBUFSIZE)
  160.  
  161. struct NetGlobal
  162. {
  163.    struct Process       *self;       /* my process                         */
  164.    struct MsgPort       *port;       /* our message port                   */
  165.    struct MsgPort       *devport;    /* msg port for device io             */
  166.    struct MsgPort       *infoport;   /* msg port for device status info    */
  167.    struct TimerPacket   *timerpkt;   /* pkt used for timer request         */
  168.    APTR                 devptr;      /* Device-defined                     */
  169.    int    run;                       /* flag to continue running           */
  170.    int    reply;                     /* flag to inhibit replying to message*/
  171.    long   ErrorCount;                /* Error count for current volume     */
  172.    short  histimeout;                /* Other side's timeout length        */
  173.    short  mytimeout;                 /* My timeout length                  */
  174.    char   *devname;                  /* pointer to device name             */
  175.    /* These are the fields of the autorequest structure we want to create  */
  176.    struct IntuiText line1;           /* Top Line of requester              */
  177.    struct IntuiText line2;           /* Second Line of requester           */
  178.    struct IntuiText line3;           /* Bottom Line of requester           */
  179.    struct IntuiText retrytxt;        /* Retry information                  */
  180.    struct IntuiText canceltxt;       /* CANCEL information                 */
  181.    char   buf3[16];                  /* Buffer to hold unit information    */
  182.    int    inuse_trans, inuse_rec;    /* NetTransInfo struct is in use      */
  183.    long   inf_trans, inf_rec;        /* Bytes trans & rec while nti in use */
  184.    struct NetTransInfo ntirec;       /* Send receive info to stat window   */
  185.    struct NetTransInfo ntitrans;     /* Send transmit info to stat window  */
  186.    union /* Union of driver-specific data - max one entry per driver */
  187.    {
  188.       struct MsgPort *LisPort;  /* For DNET protocol                   */
  189.    } d;
  190. };
  191.  
  192. typedef struct
  193. {
  194.    struct NetGlobal n;
  195.    struct RPacket RP;
  196.    struct DosPacket     *pkt;        /* the packet we are processing       */
  197. } *NGLOBAL;
  198.  
  199.